package com.controller;

import com.entity.Response;
import com.entity.pojo.LfLawyer;
import com.service.LawyerService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/lawyer")
public class LawyerController {

    @Resource
    private LawyerService lawyerService;

    @PostMapping
    public Response insertLawyer(@RequestBody LfLawyer lfLawyer) {
        int re = lawyerService.insertLawyer(lfLawyer);
        if (re > 0) {
            return new Response().setSuccess();
        } else {
            return new Response().setFailed().setErrMsg("插入失败");
        }
    }

    @GetMapping
    public Response list() {
        return new Response().setSuccess().appendMsg("list", lawyerService.listLawyer());
    }

    @DeleteMapping
    public Response delete(@RequestParam("id") Integer id) {
        int re = lawyerService.deleteLawyer(id);
        if (re > 0) {
            return new Response().setSuccess();
        } else {
            return new Response().setFailed().setErrMsg("操作失败");
        }
    }

    @PutMapping
    public Response update(@RequestBody LfLawyer lawyer) {
        int re = lawyerService.updateLawyer(lawyer);
        if (re > 0) {
            return new Response().setSuccess();
        } else {
            return new Response().setFailed().setErrMsg("操作失败");
        }
    }
}
